const app = getApp();

Page({
  data: {
    token: '',
    addressNo:true,
    addressList:[],
    id:0,
  },
  onBlur(e) {
    this.setData({
      inputValue: e.detail.value,
    });
  },
  onShareAppMessage() {
    return {
      title: '花礼鲜花玫瑰生日',
      desc: '花礼鲜花玫瑰生日',
      path: 'pages/todos/todos'
    };
  },
  onShow(){
    this.addressList();
  },
  onLoad(){
    this.addressList();
  },
  addressList(){
    var that = this;
    my.getStorage({
      key: 'token',
      success: function(res) {
        my.httpRequest({
          url: app.geturl+'/member-address/list',
          method: 'GET',
          data:{
            token:res.data.token
          },
          dataType: 'json',
          success: function(res) {
            if(res.data.code==0){
              if(res.data.data.list.length){
                that.setData({
                  addressList:res.data.data.list,
                  addressNo:true
                });
              }else{
                that.setData({
                  addressNo:false
                });
              }
            }else{
              app.memberLogin();
            }
          }
        });        
      }
    });
  },
  add() {
    app.todos = app.todos.concat([{
      text: this.data.inputValue,
      compeleted: false,
    }]);

    my.navigateBack();
  },
  checkAddress(e){
    var that = this;
    var id = e.target.dataset.id;
    my.setStorage({
      key: 'address',
      data: {
        id:id
      },
      success: function() {
        console.info('写入成功');
      }
    });
    my.navigateBack({ delta:1 });
  },
  addressEdit(e){
    var that = this;
    var id = e.target.dataset.id;
    my.navigateTo({ url: '../add-todo/address_edit?id='+id });
  },
  handleTap(){
    my.navigateTo({ url: '../todos/todos' });
  },
  addressAdd(){
    my.navigateTo({ url: '../add-todo/address_add' });
  },
});
